import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author mjy
 * @date 2021/10/26
 * @description
 */
public class MyTest {



    public static void main(String[] args) throws IOException {
        System.out.println("客户端启动");
        // 建立tcp服务
        Socket socket = new Socket("127.0.0.1",6958);
        // 获取socket输出流对象
        OutputStream outputStream = socket.getOutputStream();
        // 写数据
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        outputStream.write(s.getBytes());
        InputStream inputStream = socket.getInputStream();
        byte[] buf = new byte[1024];
        int length = inputStream.read(buf);
        System.out.println("客户端收到" + new String(buf, 0, length));
        // 关闭资源
        socket.close();
    }


}
